package IOStream.Exercise001;

import java.io.*;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/**
 * ClassName:Exercise008
 * Package:IOStream.Exercise
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/3/2-21:52
 * @Version:v1.0
 */
public class Exercise008 {
    /**
     * 修改文本顺序
     * 需求：把<出师表>的文章顺序进行恢复到一个新的文件中
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("E:\\aaa\\csb.txt"));
        String line;
        TreeMap<Integer, String> tm = new TreeMap<>();
        while ((line = br.readLine()) != null) {
            String[] arr = line.split("\\.");
            //0:序号  1:内容
            tm.put((Integer.parseInt(arr[0])), line);//arr[1]
        }
        br.close();
        //写出数据
        BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\aaa\\csbCopy002.txt"));
        Set<Map.Entry<Integer, String>> entries = tm.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            String value = entry.getValue();
            bw.write(value);
            bw.newLine();
        }
        bw.close();
    }
}
